<template>
  <div class="resgiter">
    <h2>注册</h2>
    <van-form @submit="onSubmit">
      <van-field
        v-model="phone"
        name="手机号"
        label="手机号"
        placeholder="手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { user_register } from "../api";
import { Toast } from "vant";

export default {
  data() {
    return {
      phone: "",
      password: "",
    };
  },
  methods: {
    onSubmit() {
      user_register({ phone: this.phone, pass: this.password }).then((res) => {
        Toast.success(`${res.data.msg}`);
        if (res.data.code == 200) {
          // this.$store.commit("addLolist", {
          //   phone: this.phone,
          //   pass: this.password,
          // });
          this.$router.push("/login");
        }
      });
      //   this.all=[]
    },
  },
};
</script>
<style scoped>
h2 {
  line-height: 100px;
  margin-top: 20px;
  text-align: center;
  margin-bottom: 100px;
}
</style>